package com.example.springmvcproject.Controller;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.NoHandlerFoundException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping({"${server.error.path:${error.path:/error}}"})
public class NotFoundHandle implements ErrorController {

    @RequestMapping
    public void error(HttpServletRequest request, HttpServletResponse response) throws Exception {
        throw new NoHandlerFoundException(request.getMethod(),request.getRequestURI(), (HttpHeaders) request.getHeaderNames());
    }
}
